<template>
  <t-dialog :header="getHeader" :visible.sync="visible" :onClose="closeDialog" :closeOnOverlayClick="false"
    :confirmBtn="null" width="90%" top="5%" v-if="isDialog">
    <div>
      <t-tabs placement="left" size="medium" v-model="stepValue">
        <t-tab-panel value="1" label="申报详情">
          <t-sticky-tool v-if="!hideInfo" :style="{ position: 'absolute', overflow: 'hidden', zIndex: 1000 }"
            :offset="[-40, -20]" @click="createPDF(1)">
            <t-sticky-item label="导出PDF">
              <template #icon>
                <t-icon name="file-pdf"></t-icon>
              </template>
            </t-sticky-item>
          </t-sticky-tool>
          <current-project-detail :objId="objId" :hideByProjectType="hideByProjectType" :reviewOpen="reviewOpen"
            :hideInfo="hideInfo"></current-project-detail>
        </t-tab-panel>
        <t-tab-panel value="2" label="大纲详情">
          <t-sticky-tool v-if="!hideInfo && openDG" :style="{ position: 'absolute', overflow: 'hidden', zIndex: 1000 }"
            :offset="[-40, -20]" @click="createPDF(2)">
            <t-sticky-item style="width: 80px" label="导出大纲PDF">
              <template #icon>
                <t-icon name="file-pdf"></t-icon>
              </template>
            </t-sticky-item>
          </t-sticky-tool>
          <outline-detail-dialog v-if="openDG" :hideByProjectType="hideByProjectType" :isDialog="false"
            :objId="objId"></outline-detail-dialog>
          <div v-else
            style="height: 65vh;display: flex;justify-content: center;align-items: center;font-weight: bold;font-size: 50px;color: #ccc;">
            待大纲编制...</div>
        </t-tab-panel>
        <t-tab-panel value="3" label="任务书详情">
          <t-sticky-tool v-if="!hideInfo && openRWS" :style="{ position: 'absolute', overflow: 'hidden', zIndex: 1000 }"
            :offset="[-40, -20]" @click="createPDF(3)">
            <t-sticky-item style="width: 90px" label="导出任务书PDF">
              <template #icon>
                <t-icon name="file-pdf"></t-icon>
              </template>
            </t-sticky-item>
          </t-sticky-tool>
          <contract-detail-dialog v-if="openRWS" :isDialog="false" :objId="objId"></contract-detail-dialog>
          <div v-else
            style="height: 65vh;display: flex;justify-content: center;align-items: center;font-weight: bold;font-size: 50px;color: #ccc;">
            待签订任务书...</div>
        </t-tab-panel>
        <t-tab-panel value="4" label="实施变更申请">
          <change-apply-list :projectId="objId"></change-apply-list>
        </t-tab-panel>
        <t-tab-panel value="5" label="验收详情">
          <acceptance-detail-dialog v-if="openYS" :isDialog="false" :row="row"
            :objId="objId"></acceptance-detail-dialog>
          <div v-else
            style="height: 65vh;display: flex;justify-content: center;align-items: center;font-weight: bold;font-size: 50px;color: #ccc;">
            待验收申请...</div>
        </t-tab-panel>
        <!--        <t-tab-panel value="5" label="实施管理">-->
        <!--          <implement-detail :objId="objId"></implement-detail>-->
        <!--&lt;!&ndash;          <div  style="height: 65vh;display: flex;justify-content: center;align-items: center;font-weight: bold;font-size: 50px;color: #ccc;">待开发...</div>&ndash;&gt;-->
        <!--        </t-tab-panel>-->
        <!-- <t-tab-panel  value="6" label="实施执行情况报告">
          <performance-report-list :projectId="objId"></performance-report-list>
        </t-tab-panel>
        <t-tab-panel value="7" label="年度经济效益">
          <project-benefit :objId="objId" :project-name="getHeader" :edit-open="true"></project-benefit>
        </t-tab-panel> -->
      </t-tabs>
    </div>
  </t-dialog>
  <t-tabs v-else :size="size" v-model="tabValue">
    <!--    <t-tab-panel value="first" label="申报单位信息" :destroyOnHide="true">-->
    <!--    </t-tab-panel>-->
    <t-tab-panel :class="[reviewOpen ? 'tab-full-panel' : 'tab-panel']" value="1" label="基本信息" :destroyOnHide="true">
      <t-form labelWidth="160px">
        <t-row style="align-items: stretch" :gutter="14">
          <t-col :span="6">
            <t-card class="step-card" size="small" title="基本信息">
              <t-form-item label="项目编号：" name="projectNum">
                {{ data.projectNum || '暂未分配' }}
              </t-form-item>
              <t-form-item label="项目名称：" name="projectName">
                {{ data.projectName }}
              </t-form-item>
              <t-form-item v-if="!hideInfo" label="承担单位：">
                {{ data.declareDeptName }}
              </t-form-item>
              <t-form-item v-if="site_tag === 'jtt'" label="计划类别：" name="projectCategory">
                {{ data.projectCategory | filterByTree(projectCategoryOptions) }}
                <!--                  <t-tree-select disabled clearable v-model="data.projectCategory" :treeProps="{keys: {value: 'id'}}"-->
                <!--                                 :data="projectCategoryOptions" style="width: 390px"></t-tree-select>-->
              </t-form-item>
              <t-form-item label="学科分类：" name="subjectClassification">
                {{ data.subjectClassification | filterByDict(dict.type.subject_classification) }}
              </t-form-item>

              <t-form-item label="项目类型：" name="projectType">
                {{ data.projectType | filterByDict(dict.type.project_type) }}
              </t-form-item>
              <!--                <t-form-item label="平台类型：" name="platformType">-->
              <!--                  {{data.platformType | filterByDict(dict.type.platform_type)}}-->
              <!--                </t-form-item>-->
              <t-form-item label="申报日期：" name="declareDate">
                {{ data.declareDate }}
              </t-form-item>
              <t-form-item label="项目开始时间：" name="startDate">
                {{ data.startDate }}
              </t-form-item>
              <t-form-item label="项目结束时间：" name="endDate">
                {{ data.endDate }}
              </t-form-item>
              <t-form-item label="关键词：" name="keyWord">
                {{ data.keyWord }}
              </t-form-item>
              <t-form-item label="建议经费总概算：" name="adviceFunding">
                {{ data.adviceFunding }}万元
              </t-form-item>
              <t-form-item :label="site_tag === 'jtt' ? '申请厅补助经费：' : '申请集团补助经费'" name="subsidyFunding">
                {{ data.subsidyFunding }}万元
              </t-form-item>
              <t-form-item label="自筹经费：" name="zcFunding">
                {{ (data.adviceFunding * 100 - data.subsidyFunding * 100) / 100 }}万元
              </t-form-item>
              <t-form-item v-if="site_tag === 'jt'" label="是否高速公路项目：" name="isRoadProject">
                <template v-if="data.isRoadProject === '1'">是</template>
                <template v-else>否</template>
                <!--                        <t-radio-group disabled v-model="data.isRoadProject" :options="[{label:'是',value:'1'},{label:'否',value:'0'}]"></t-radio-group>-->
              </t-form-item>
              <t-form-item v-if="site_tag === 'jt' && data.isRoadProject === '1'" label="高速路段：" name="expresswayId">
                {{ data.expresswayId | filterParentsByTree(expresswayOptions) }}
              </t-form-item>
              <t-form-item v-if="site_tag === 'jt' && data.isRoadProject === '1'" label="编号：" name="sysExpressway.code">
                {{ data.sysExpressway.code }}
              </t-form-item>
              <!--                <t-form-item v-if="site_tag==='jt' && data.isRoadProject==='1'" label="起点桩号：" name="sysExpressway.startNum">-->
              <!--                  {{data.sysExpressway.startNum}}（{{data.startPointX}},{{data.startPointY}}）-->
              <!--                </t-form-item>-->
              <!--                <t-form-item v-if="site_tag==='jt' && data.isRoadProject==='1'" label="终点桩号：" name="sysExpressway.endNum">-->
              <!--                  {{data.sysExpressway.endNum}}（{{data.endPointX}},{{data.endPointY}}）-->
              <!--                </t-form-item>-->
            </t-card>
          </t-col>
          <t-col :span="6">
            <t-card class="step-card" size="small" title="项目组情况">
              <t-form-item label="总人数：" name="projectTeam.totalCount">
                {{ data.projectTeam.totalCount }}
              </t-form-item>
              <t-form-item label="高级职称人数：" name="projectTeam.highCount">
                {{ data.projectTeam.highCount }}
              </t-form-item>
              <t-form-item label="中级职称人数：" name="projectTeam.middleCount">
                {{ data.projectTeam.middleCount }}
              </t-form-item>
              <t-form-item label="初级职称人数：" name="projectTeam.primaryCount">
                {{ data.projectTeam.primaryCount }}
              </t-form-item>
              <t-form-item label="研究生人数：" name="projectTeam.postgraduate">
                {{ data.projectTeam.postgraduate }}
              </t-form-item>
              <t-form-item label="辅助人员人数：" name="projectTeam.auxilian">
                {{ data.projectTeam.auxilian }}
              </t-form-item>
            </t-card>
          </t-col>
        </t-row>
        <t-row style="align-items: stretch" :gutter="14" v-if="!hideInfo">
          <t-col :span="6">
            <t-card class="step-card" size="small" title="项目负责人">
              <t-form-item label="姓名：" name="projectLeader.name">
                {{ data.projectLeader.name }}
              </t-form-item>
              <t-form-item label="性别：" name="projectLeader.sex">
                {{ data.projectLeader.sex | filterByDict(dict.type.sys_user_sex) }}
              </t-form-item>
              <t-form-item label="身份证号：" name="projectLeader.idCard">
                {{ data.projectLeader.idCard }}
              </t-form-item>
              <t-form-item label="出生年月：" name="projectLeader.birthDate">
                {{ data.projectLeader.birthDate }}
              </t-form-item>
              <t-form-item label="工作单位：" name="projectLeader.companyId">
                {{ data.projectLeader.company }}
              </t-form-item>
              <!--                <t-form-item label="归口单位：" name="projectLeader.companyId">-->
              <!--                  {{data.attributeDeptName}}-->
              <!--                </t-form-item>-->
              <t-form-item label="联系电话：" name="projectLeader.phone">
                {{ data.projectLeader.phone }}
              </t-form-item>
              <t-form-item label="通讯地址：" name="projectLeader.address">
                {{ data.projectLeader.address }}
              </t-form-item>
              <t-form-item label="电子信箱：" name="projectLeader.email">
                {{ data.projectLeader.email }}
              </t-form-item>
              <t-form-item label="邮编：" name="projectLeader.postCode">
                {{ data.projectLeader.postCode }}
              </t-form-item>
              <t-form-item label="毕业院校：" name="projectLeader.school">
                {{ data.projectLeader.school }}
              </t-form-item>
              <t-form-item label="学历：" name="projectLeader.education">
                {{ data.projectLeader.education | filterByDict(dict.type.education) }}
              </t-form-item>
              <t-form-item label="学位：" name="projectLeader.degree">
                {{ data.projectLeader.degree | filterByDict(dict.type.degree) }}
              </t-form-item>
              <t-form-item label="所学专业：" name="projectLeader.majorName">
                {{ data.projectLeader.majorName }}
              </t-form-item>
              <t-form-item label="现从事专业：" name="projectLeader.majorNowName">
                {{ data.projectLeader.majorNowName }}
              </t-form-item>
              <t-form-item label="职务：" name="projectLeader.duty">
                {{ data.projectLeader.duty }}
              </t-form-item>
              <t-form-item label="技术职称：" name="projectLeader.profTitId">
                {{ data.projectLeader.profTitId | filterByTree(profTitOptions) }}
              </t-form-item>
              <t-form-item label="职称：" name="projectLeader.profTit">
                {{ data.projectLeader.profTit | filterByDict(dict.type.prof_tit) }}
              </t-form-item>
              <t-form-item label="在本项目中承担的任务：" name="projectLeader.task">
                {{ data.projectLeader.task }}
              </t-form-item>
            </t-card>
          </t-col>
          <t-col :span="6">
            <t-card class="step-card" size="small" title="项目联系人">
              <t-form-item label="姓名：" name="projectLinker.name">
                {{ data.projectLinker.name }}
              </t-form-item>
              <t-form-item label="联系电话：" name="projectLinker.phone">
                {{ data.projectLinker.phone }}
              </t-form-item>
              <t-form-item label="通信地址：" name="projectLinker.address">
                {{ data.projectLinker.address }}
              </t-form-item>
              <t-form-item label="电子信箱：" name="projectLinker.email">
                {{ data.projectLinker.email }}
              </t-form-item>
              <t-form-item label="邮编：" name="projectLinker.postCode">
                {{ data.projectLinker.postCode }}
              </t-form-item>
            </t-card>
          </t-col>
        </t-row>
      </t-form>
    </t-tab-panel>
    <t-tab-panel :class="[reviewOpen ? 'tab-full-panel' : 'tab-panel']" value="2" label="立项背景和依据" :destroyOnHide="true">
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="（一）研究背景">
            <!--              <div class="content_style"  v-html="data.projectBackground.background"></div>-->
            <inner-html :content="data.projectBackground.background"></inner-html>

          </t-card>

        </t-col>
      </t-row>
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="（二）研究目的与意义">
            <!--              <div class="content_style"  v-html="data.projectBackground.goal"></div>-->
            <inner-html :content="data.projectBackground.goal"></inner-html>

          </t-card>
        </t-col>
      </t-row>
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="（三）国内外研究现状与评价">
            <!--              <div class="content_style"  v-html="data.projectBackground.actuality"></div>-->
            <inner-html :content="data.projectBackground.actuality"></inner-html>

          </t-card>
        </t-col>
      </t-row>
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="（四）主要参考文献">
            <project-background-literature phaseType="1" ref="project-background-literature" :projectId="objId"
              v-model="data.projectBackground.literatures" :editOpen="false"></project-background-literature>
          </t-card>
        </t-col>
      </t-row>
    </t-tab-panel>
    <t-tab-panel :class="[reviewOpen ? 'tab-full-panel' : 'tab-panel']" value="3" label="研究方案" :destroyOnHide="true">
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="（一）研究内容、拟解决的关键问题、研究方法、技术路线及创新点">
            <!--              <div class="content_style"  v-html="data.projectApproach.researchContent"></div>-->
            <inner-html :content="data.projectApproach.researchContent"></inner-html>

          </t-card>
        </t-col>
      </t-row>
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="（二）年度研究计划（包括起止年月、计划内容）">
            <project-research-plan v-model="data.projectApproach.projectResearchPlan" :disableDate="disableDate"
              :projectId="objId" :editOpen="false" phaseType="1"></project-research-plan>
          </t-card>
        </t-col>
      </t-row>
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="（三）预期研究成果及表达形式">
            <!--              <div v-html="data.projectApproach.expectedResults"></div>-->
            <project-approach-expect-results phaseType="1" :projectId="objId" ref="project-approach-expect-results"
              v-model="data.projectApproach.projectExpectResults" :editOpen="false"></project-approach-expect-results>
          </t-card>
        </t-col>
      </t-row>
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="（四）项目预期目标及经济、社会效益">
            <!--              <div class="content_style"  v-html="data.projectApproach.expectedGoal"></div>-->
            <inner-html :content="data.projectApproach.expectedGoal"></inner-html>

          </t-card>
        </t-col>
      </t-row>
    </t-tab-panel>
    <t-tab-panel :class="[reviewOpen ? 'tab-full-panel' : 'tab-panel']" value="4" label="研究基础" :destroyOnHide="true">
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small"
            title="（一）与本项目有关的研究工作积累和已取得的研究工作成就（包括近期发表的与本项目有关的论文、出版的主要论著、获得的学术奖励、已完成和在研的研究项目等）">
            <!--              <div class="content_style" v-html="data.projectBasicstudy.achievement"></div>-->
            <inner-html :content="data.projectBasicstudy.achievement"></inner-html>

          </t-card>
        </t-col>
      </t-row>
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="（二）项目依托工程情况及其它必要支撑条件（包括依托工程的概况，投资来源，工程进度与项目科研进度的配合情况）">
            <!--              <div class="content_style" v-html="data.projectBasicstudy.conditions"></div>-->
            <inner-html :content="data.projectBasicstudy.conditions"></inner-html>

          </t-card>
        </t-col>
      </t-row>
    </t-tab-panel>
    <t-tab-panel :class="[reviewOpen ? 'tab-full-panel' : 'tab-panel']" value="5" label="单位信息" :destroyOnHide="true"
      v-if="!hideInfo">
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <project-unit v-model="data.projectCompanyList" :projectId="objId" :adviceFunding="data.adviceFunding"
            :editOpen="false" phaseType="1"></project-unit>
        </t-col>
      </t-row>
    </t-tab-panel>
    <t-tab-panel :class="[reviewOpen ? 'tab-full-panel' : 'tab-panel']" value="6" label="研究人员" :destroyOnHide="true"
      v-if="!hideInfo && !(hideByProjectType && data.projectType === '08')">
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <project-member v-model="data.projectMembers" :projectId="objId" :editOpen="false"
            phaseType="1"></project-member>
        </t-col>
      </t-row>
    </t-tab-panel>
    <t-tab-panel :class="[reviewOpen ? 'tab-full-panel' : 'tab-panel']" value="7" label="经费预算" :destroyOnHide="true">
      <project-budget v-model="data.projectBudget" :container="'.t-tab-panel'" :projectId="objId"
        :fundingObj="fundingObj" :editOpen="false" phaseType="1"></project-budget>
    </t-tab-panel>
    <t-tab-panel :class="[reviewOpen ? 'tab-full-panel' : 'tab-panel']" value="8" label="附件信息" :destroyOnHide="true"
      v-if="!hideInfo">
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-table row-key="id" :columns="projectFileColumns" :data="projectFileData">
            <template #id="{ row, rowIndex }">
              {{ rowIndex + 1 }}
            </template>
            <template #c1="{ row }">
              <a v-if="row.c3" class="t-button-link" :href="`${file_domain}/${row.c3}`" target="_blank">{{ row.c1 }}</a>
              <div v-else>{{ row.c1 }}</div>
            </template>
            <template #op="{ row }">
              <div v-for="(item, index) in row.fileLists" :key="index">
                <a class="t-button-link" target="_blank" :href="item.url">
                  {{ item.name }}
                </a>
              </div>
            </template>
          </t-table>
        </t-col>
      </t-row>
    </t-tab-panel>
  </t-tabs>
</template>

<script>
import { VITE_FILE_DOMAIN } from '@/api/upload'
import ProjectResearchPlan from './project-research-plan.vue'
import ProjectBackgroundLiterature from "./project-background-literature.vue";
import ProjectApproachExpectResults from "./project-approach-expectResults.vue";
import ProjectUnit from './project-unit.vue'
import ProjectMember from './project-member.vue'
import ProjectBudget from './project-budget.vue'
import FileUpload from "@/components/FileUpload/index.vue"
import InnerHtml from "@/components/InnerHtml/index.vue";
import { getFiles } from "@/api/common";
import dayjs from "dayjs";
import OutlineDetailDialog from "../../outline/components/outline-detail-dialog.vue";
import ContractDetailDialog from "../../contract/components/contract-detail-dialog.vue";
import AcceptanceDetailDialog from "../../acceptance/components/acceptance-detail-dialog.vue";
import ProjectBenefit from "../../achievement/components/project-benefit.vue";
import ImplementDetail from "../../implement/components/implement-detail.vue";
import ChangeApplyList from "../../implement/components/change-apply-list.vue";
import performanceReportList from "../../implement/components/performance-report-list.vue";
import currentProjectDetail from "@/pages/kjxm/apply/components/project-detail.vue";

export default {
  name: "project-detail",
  dicts: ["project_type", "subject_classification", "sys_user_sex", "prof_tit", "degree", "duty", "platform_type", "member_type", "expect_result_type", "education"],
  components: {
    ProjectResearchPlan,
    ProjectUnit,
    ProjectMember,
    ProjectBudget,
    ProjectBackgroundLiterature,
    ProjectApproachExpectResults,
    FileUpload,
    OutlineDetailDialog,
    ContractDetailDialog,
    AcceptanceDetailDialog,
    ProjectBenefit,
    InnerHtml,
    ImplementDetail,
    ChangeApplyList,
    performanceReportList,
    currentProjectDetail
  },
  props: {
    objId: [String, Number],
    approveType: String,
    // header: String,
    isDialog: {
      type: Boolean,
      default: true
    },
    row: Object,
    hideInfo: {
      type: Boolean,
      default: false
    },
    hideByProjectType: {
      type: Boolean,
      default: false
    },
    size: {
      type: String,
      default: 'large'
    },
    reviewOpen: {
      type: Boolean,
      default: false
    },
    isReview: {
      type: Boolean,
      default: false
    },
    tabDefaultValue: {
      type: String,
      default: '1'
    }
  },
  data () {
    return {
      file_domain: VITE_FILE_DOMAIN,
      expresswayOptions: [],
      isMyProject: false,
      openDG: false,
      openRWS: false,
      openYS: false,
      stepValue: this.tabDefaultValue,
      header: '',
      dgHeader: '',
      rwsHeader: '',
      fundingObj: { subsidyFunding: 0, adviceFunding: 0 },
      disableDate: {},
      profTitOptions: [],
      expectedResultsColumns: [
        {
          colKey: "sort",
          title: "序号",
          width: 64,
          align: "center",
        },
        {
          colKey: "expectResultTypeLabel",
          title: "成果类型",
          align: "center",
        },
        {
          colKey: "count",
          title: "数量",
          align: "center",
        },
      ],
      site_tag: import.meta.env.VITE_SITE_TAG,
      visible: true,
      tabValue: "1",
      projectFileColumns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 64
        },
        {
          colKey: "c1",
          title: "附件名称",
          align: "center",
        },
        {
          colKey: "c2",
          title: "是否必需",
          align: "center",
        },
        {
          colKey: "op",
          title: "附件列表",
          align: "left",
        },
      ],
      projectFileData: [
        {
          id: 1,
          c1: "查新报告",
          c2: "是",
          moduleKey: "projectCXBG",
          fileIds: [],
          fileLists: [],
        },
        {
          id: 2,
          c1: "归口管理单位科研诚信承诺书(模版)",
          c2: "是",
          c3: 'view/模板/归口管理单位科研诚信承诺书.pdf',
          fileIds: [],
          fileLists: [],
          moduleKey: "projectCNS"
        },
        {
          id: 3,
          c1: "项目组科研诚信承诺书(模版)",
          c2: "是",
          c3: 'view/模板/项目组科研诚信承诺书.pdf',
          fileIds: [],
          fileLists: [],
          moduleKey: "projectTeamCNS"
        },
        {
          id: 4,
          c1: "已盖章申报书",
          c2: "所有申报流程审批通过后，从系统导出PDF线下盖章(申报用户上传)",
          fileIds: [],
          fileLists: [],
          moduleKey: "projectSBS"
        },
        {
          id: 6,
          c1: "其他",
          c2: "否",
          moduleKey: "projectQT",
          fileIds: [],
          fileLists: [],
          require: false,
        },
      ],
      data: {
        projectCategory: '',
        projectTeam: {},
        projectLeader: {},
        projectLinker: {},
        projectBackground: {
          background: ''
        },
        projectApproach: {
          projectExpectResults: []
        },
        projectBasicstudy: {},
        projectCompanyList: [],
        projectMembers: [],
        projectBudget: {},
        deptName: '',
        sysExpressway: {
          code: '',
          startNum: '',
          endNum: '',
        }
      },
      projectCategoryOptions: []
    }
  },
  computed: {
    getHeader () {
      let header = ''
      if (this.rwsHeader) {
        header = this.rwsHeader
      }
      if (this.dgHeader && !this.rwsHeader) {
        header = this.dgHeader
      }
      if (this.header && !this.rwsHeader && !this.dgHeader) {
        header = this.header
      }
      return header
    }
  },
  watch: {
    objId: {
      immediate: true,
      handler (val) {
        if (val) {
          this.getObj(val);
        }
      }
    },
  },
  methods: {
    createPDF (type) {
      const instance = this.$loading({
        fullscreen: true,
        attach: 'body',
        preventScrollThrough: false,
      });
      if (type === 1) {


        this.$api.kjxm.project.projectTestPDF(this.objId).then(response => {
          window.open(response.data.fullFilePath, '_blank')
          instance.hide();
        }).catch((e) => {
          instance.hide();
          this.$message.error(e.toString());
        });
      } else if (type === 2) {
        this.$api.kjxm.outline.createPDF(this.objId, this.isReview ? 2 : 1).then(response => {
          window.open(response.data.fullFilePath, '_blank')
          instance.hide();
        }).catch((e) => {
          instance.hide();
          this.$message.error(e.toString());
        });
      } else if (type === 3) {
        this.$api.kjxm.contract.createPDF(this.objId, this.isReview ? 2 : 1).then(response => {
          window.open(response.data.fullFilePath, '_blank')
          instance.hide();
        }).catch((e) => {
          instance.hide();
          this.$message.error(e.toString());
        });
      }

    },
    uploadSuccess (ids) {
      this.$api.kjxm.project.edit({
        id: this.objId,
        sysAttMainVo: {
          sysAttMainIds: ids,
        }
      }).then(val => {
        this.$message.success("上传成功");
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    async getObj () {
      Promise.all([this.getDeclareTree(), this.getprofTitTreeSelect(), this.getExpresswayTreeSelect()]);
      this.checkDG();
      this.checkRWS();
      this.checkYS();
      if (this.hideInfo) {
        this.$api.kjxm.project.getAllHide(this.objId).then(response => {
          this.header = response.data.projectName;
          const isMyProject = this.$store.state.user.userId === response.data.createUserId;
          // const isProjectSBS = isOwner && Number(response.data.projectStatus || 0)>=6 && Number(response.data.projectStatus || 0)!==7;
          // 从单位里面找出承担单位
          // const companyData = response.data.projectCompanyList.filter((val) => val.type === '1');
          // if(companyData.length>0){
          //   this.data.deptName = companyData[0].name;
          // }
          response.data.projectMembers = response.data.projectMembers || []
          this.disableDate = {
            before: dayjs(response.data.startDate, "YYYY-MM-DD").endOf('month').subtract(1, 'month').format(),
            after: dayjs(response.data.endDate, "YYYY-MM-DD").endOf('month').subtract(0, 'month').format(),
          }
          this.fundingObj = {
            adviceFunding: response.data.adviceFunding,
            subsidyFunding: response.data.subsidyFunding
          }
          Object.assign(this.data, response.data)
        }).catch((e) => {
          this.$message.error(e.toString());
        });
      } else {
        this.$api.kjxm.project.getAll(this.objId).then(response => {
          if (response.data.createUserId === Number(this.$store.state.user.userId)) {
            this.isMyProject = true;
          }
          this.header = response.data.projectName;
          const isOwner = this.$store.state.user.userId === response.data.createUserId;
          // const isProjectSBS = Number(response.data.projectStatus || 0)>=6 && Number(response.data.projectStatus || 0)!==7;
          // 从单位里面找出承担单位
          // const companyData = response.data.projectCompanyList.filter((val) => val.type === '1');
          // if(companyData.length>0){
          //   this.data.deptName = companyData[0].name;
          // }




          response.data.projectMembers = response.data.projectMembers || []
          this.disableDate = {
            before: dayjs(response.data.startDate, "YYYY-MM-DD").endOf('month').subtract(1, 'month').format(),
            after: dayjs(response.data.endDate, "YYYY-MM-DD").endOf('month').subtract(0, 'month').format(),
          }
          this.fundingObj = {
            adviceFunding: response.data.adviceFunding,
            subsidyFunding: response.data.subsidyFunding
          }
          Object.assign(this.data, response.data)
          // 如果是高速公路项目
          if (this.data.isRoadProject === '1') {

          }




          // 获取项目附件
          getFiles(this.objId).then((res) => {
            const files = {}
            res.data.forEach((item) => {
              if (!files[item.moduleKey]) {
                files[item.moduleKey] = []
              }
              files[item.moduleKey].push({
                name: item.fileName,
                url: item.fullFilePath,
                id: item.id,
                filePath: item.filePath
              })
            })
            // this.projectFileData[0].fileLists = files.projectCXBG || [];
            // this.projectFileData[1].fileLists = files.projectCNS || [];
            // this.projectFileData[2].fileLists = files.projectTeamCNS || [];
            // // this.projectFileData[3].fileLists = files.projectSBS || [];
            // this.projectFileData[0].fileIds = files.projectCXBG?.map(val => val.id) || [];
            // this.projectFileData[1].fileIds = files.projectCNS?.map(val => val.id) || [];
            // this.projectFileData[2].fileIds = files.projectTeamCNS?.map(val => val.id) || [];
            // // this.projectFileData[3].fileIds = files.projectSBS?.map(val => val.id) || [];
            // // if(isProjectSBS){
            // //
            // // }
            // this.projectFileData[3].fileLists = files.projectSBS || [];
            // this.projectFileData[3].fileIds = files.projectSBS?.map(val => val.id) || [];

            // 查新报告非必填
            if (this.site_tag === 'jt') {
              this.$set(this.projectFileData[0], 'c2', '否')
              this.$set(this.projectFileData[0], 'require', false)
              this.projectFileData.splice(3, 0, {
                id: 5,
                c1: "集团各直属单位（即项目归口管理单位）应对项目申报材料进行审查并提出书面审查意见，未经审查项目不得申报，需盖公章。",
                c2: "归口管理单位审批通过后上传(归口管理单位审批时上传)",
                fileIds: [],
                fileLists: [],
                moduleKey: "projectSMSCYJ",
                require: false,
              })
              const item = this.projectFileData.splice(0, 1);
              this.projectFileData.splice(3, 0, item[0]);
              this.projectFileData.shift();
              this.projectFileData.shift();
            }
            this.projectFileData.forEach((val, index) => {
              this.projectFileData[index].fileLists = files[val.moduleKey] || [];
              this.projectFileData[index].fileIds = files[val.moduleKey]?.map(val => val.id) || [];
            })
          }).catch((e) => {
            this.$message.error(e.toString());
          });
        }).catch((e) => {
          this.$message.error(e.toString());
        });
      }
    },
    checkDG () {
      this.$api.kjxm.outline.getByProject(this.objId).then(response => {
        if (response.data) {
          this.openDG = true
          this.dgHeader = response.data.projectName;
        }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    checkRWS () {
      this.$api.kjxm.contract.getByProject(this.objId).then(response => {
        if (response.data) {
          this.openRWS = true
          this.rwsHeader = response.data.projectName;
        }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    checkYS () {
      this.$api.kjxm.acceptance.getByProject(this.objId).then(response => {
        if (response.data) {
          this.openYS = true
        }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getDeclareTree () {
      return this.$api.kjxm.project.planCategoryTree().then(response => {
        this.projectCategoryOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getExpresswayTreeSelect () {
      return this.$api.system.expressway.treeSelect().then(
        (res) => {
          this.expresswayOptions = res.data;
        }).catch((e) => {
          this.$message.error(e.toString());
        });
    },
    getprofTitTreeSelect () {
      return this.$api.system.profTit.treeselect().then(response => {
        this.profTitOptions = response.data;
        // this.profTitOptions = this.handleTree(response.data, "id");
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    closeDialog () {
      this.$emit("update:visible", false);
    },
  }
}
</script>

<style lang="less" scoped>
.t-tab-panel {
  padding: 10px;
}

.tab-panel {
  height: calc(65vh - 64px);
  overflow: scroll;
}

.tab-full-panel {
  height: calc(80vh - 64px);
  overflow: scroll;
}

.t-form__item {
  margin-bottom: 6px
}

.t-row {
  margin-bottom: 14px;
}

.step-card {
  height: 100%;
  margin-bottom: 14px;
}

.content_style {
  font-size: 12pt;
  font-family: 宋体;
  line-height: 1.5;
}
</style>
